import { EventEmitter } from '../../engine/common/event-emmiter';
import { Model } from './model';

export class CanvasModel extends Model {
  #isAnyKeyPressed = false;
  #isLoading = false;
  #isVictorious: boolean | null = null;

  readonly onStateChanged = new EventEmitter<CanvasModel>();

  get isAnyKeyPressed(): boolean {
    return Boolean(this.#isAnyKeyPressed);
  }

  get isLoading(): boolean {
    return this.#isLoading;
  }

  get isVictorious(): boolean | null {
    return this.#isVictorious;
  }

  start() {
    this.#isAnyKeyPressed = false;
    this.onStateChanged.emit(this);
  }

  changeLoading(isLoading: boolean) {
    this.#isLoading = isLoading;
    this.onStateChanged.emit(this);
  }

  pressAnyKey() {
    this.#isAnyKeyPressed = true;
    this.onStateChanged.emit(this);
  }

  finish(isVictorious: boolean) {
    this.#isVictorious = isVictorious;
    this.onStateChanged.emit(this);
  }
}
